package com.security.demo.code;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * @author td
 * @date 2017/10/24
 */
public class ImageCode {

    private BufferedImage image;

    private String code;
    /**
     * 验证码过期时间
     */
    private LocalDateTime expireTime;


    public ImageCode(BufferedImage image,String code,long expireIn ) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ImageCode(BufferedImage image, String code, LocalDateTime expireTime) {
        this.image = image;
        this.code = code;
        this.expireTime = expireTime;
    }

    public boolean isExpire() {

        // 验证码当前时间在expireTime之后就是过期的
        return LocalDateTime.now().isAfter(expireTime);
    }



    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }
}
